#include <all_wlib.h>
#pragma hdrstop
//#pragma package(smart_init)
#pragma resource "*.dfm"
#pragma link "HWindow"
#pragma link "ozf_Base"
#pragma link "HRectButton"

#include "ozf_Speed.h"

DEF_SWITCH( Speed )

//---------------------------------------------------------------------------
__fastcall TSpeedForm::TSpeedForm(TComponent* Owner)
    : TOziBaseForm(Owner )
  {
     FColorLight = -1;
     FSpeed      = 0;
     panImg->DoubleBuffered = true;

//CFG
     Init( "Speed", (TForm**)&Form );
     ColorLight           = GOPT( "Speed/Color",    10 );
     panControls->Visible = GOPT( "Speed/CVisible", panControls->Visible );
}

void __fastcall TSpeedForm::idPos( double Lat,double Lon,double vSpeed,double Head,double Mag,double Alt, int x, int y )
  {
    Speed = vSpeed;
    image->Invalidate();
}

DECL_PROP_SET( TSpeedForm, int, ColorLight )
  {
    if ( FColorLight == val ) return;
    FColorLight = val;

    pgColor->Position = val;
    image->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TSpeedForm::FormClose(TObject *Sender, TCloseAction &Action)
  {
  //CFG
     SOPT( "Speed/Color",    ColorLight );
     SOPT( "Speed/CVisible", panControls->Visible );
  //Base
     TOziBaseForm::FormClose( Sender, Action );
}
//---------------------------------------------------------------------------
void __fastcall TSpeedForm::pgColorChange(TObject *Sender)
  {
    ColorLight = pgColor->Position;
}
//---------------------------------------------------------------------------
void __fastcall TSpeedForm::idColorLess(TObject *Sender)
  {
    pgColor->Position = pgColor->Position-1;
}
//---------------------------------------------------------------------------
void __fastcall TSpeedForm::idColorMore(TObject *Sender)
{
    pgColor->Position = pgColor->Position+1;
}
//---------------------------------------------------------------------------
void __fastcall TSpeedForm::imagePaint(TObject *Sender)
  {  TCanvas *dc = image->Canvas;
     MyRect   r( 0,0,image->Width,image->Height );

     dc->Font->Size  = Max( 8,r.Height()-20 ) & (~1);
     dc->Font->Color = (TColor)RGB( 0,ColorLight*16-1,0 );
     TC_Fill( dc,r,clBlack );
     TC_TextOut( dc, r, Message("%3.1lf",Speed), clNone, DT_SINGLELINE|DT_VCENTER|DT_RIGHT);
}
//---------------------------------------------------------------------------
void __fastcall TSpeedForm::idOnButton( TObject *Sender, const PHCustomWindowBorder Border, const HCaptionButton_t Button )
{
     if ( Button == hcbHelp )
       panControls->Visible = !panControls->Visible;
     TOziBaseForm::idOnButton( Sender, Border, Button );
}
//---------------------------------------------------------------------------
void __fastcall TSpeedForm::FormKeyDown( TObject *Sender, WORD &Key, TShiftState Shift )
  {
     if ( Key == VK_ADD )      idColorMore(NULL); else
     if ( Key == VK_SUBTRACT ) idColorLess(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TSpeedForm::FormKeyPress(TObject *Sender, char &Key)
  {
     if ( Key == '+' || Key == '=' ) idColorMore(NULL); else
     if ( Key == '-' )               idColorLess(NULL);
}
//---------------------------------------------------------------------------
